{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b4b4f86b-a639-4338-91e1-21bef8de6781",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-01T09:45:35.222451Z",
     "iopub.status.busy": "2022-04-01T09:45:35.221996Z",
     "iopub.status.idle": "2022-04-01T09:45:35.356727Z",
     "shell.execute_reply": "2022-04-01T09:45:35.356003Z",
     "shell.execute_reply.started": "2022-04-01T09:45:35.222377Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "34226f73-0f40-4700-856b-aedaae5587e7",
   "metadata": {},
   "source": [
    "## 小结\n",
    "1. 最外层括号对应axis=0，依次往里的括号对应axis的取值加1\n",
    "2. 操作对应的是当前括号下的直接子元素\n",
    "    1. 如果直接子元素是数，那就是在所有数上的操作\n",
    "    2. 如果直接子元素是数组，那就是找到对应位置的数上的操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2e5482d1-070a-4835-b23e-30e1b2ed4c0a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-01T09:46:59.061440Z",
     "iopub.status.busy": "2022-04-01T09:46:59.061190Z",
     "iopub.status.idle": "2022-04-01T09:46:59.071739Z",
     "shell.execute_reply": "2022-04-01T09:46:59.071139Z",
     "shell.execute_reply.started": "2022-04-01T09:46:59.061414Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1],\n",
       "       [2, 3]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生成二维数组\n",
    "arr = np.arange(0,4).reshape(2,2)\n",
    "arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "767d0669-ac1a-4fb9-ae32-6aba3329c6ec",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-01T09:56:49.608212Z",
     "iopub.status.busy": "2022-04-01T09:56:49.607897Z",
     "iopub.status.idle": "2022-04-01T09:56:49.613308Z",
     "shell.execute_reply": "2022-04-01T09:56:49.612639Z",
     "shell.execute_reply.started": "2022-04-01T09:56:49.608182Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 4])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# axis=0,求和计算\n",
    "arr.sum(axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "bb77a1d7-e48e-4cf8-ae1f-3d9833f8d934",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-01T10:03:58.248860Z",
     "iopub.status.busy": "2022-04-01T10:03:58.248605Z",
     "iopub.status.idle": "2022-04-01T10:03:58.253628Z",
     "shell.execute_reply": "2022-04-01T10:03:58.252946Z",
     "shell.execute_reply.started": "2022-04-01T10:03:58.248833Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 5])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# axis=1,求和计算\n",
    "arr.sum(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "7697d6fd-47aa-4faf-9937-5886a30ff95c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-01T10:11:58.333633Z",
     "iopub.status.busy": "2022-04-01T10:11:58.333380Z",
     "iopub.status.idle": "2022-04-01T10:11:58.339200Z",
     "shell.execute_reply": "2022-04-01T10:11:58.338175Z",
     "shell.execute_reply.started": "2022-04-01T10:11:58.333607Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4,  5],\n",
       "       [ 6,  7,  8,  9, 10, 11]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生成二维数组\n",
    "arr1 = np.arange(12).reshape(2,6)\n",
    "arr1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "dd7f3118-e3d8-4a17-8b7c-bfbdaa8995ae",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-01T10:13:28.366448Z",
     "iopub.status.busy": "2022-04-01T10:13:28.366192Z",
     "iopub.status.idle": "2022-04-01T10:13:28.371219Z",
     "shell.execute_reply": "2022-04-01T10:13:28.370539Z",
     "shell.execute_reply.started": "2022-04-01T10:13:28.366421Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 求所有元素的max\n",
    "arr1.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "58e8f5e7-815d-462a-a6ae-c804cb633202",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-01T10:16:24.294509Z",
     "iopub.status.busy": "2022-04-01T10:16:24.294040Z",
     "iopub.status.idle": "2022-04-01T10:16:24.299603Z",
     "shell.execute_reply": "2022-04-01T10:16:24.299022Z",
     "shell.execute_reply.started": "2022-04-01T10:16:24.294481Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 6,  7,  8,  9, 10, 11])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# axis=0，做max操作\n",
    "arr1.max(axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "5985f1cc-0e31-420b-af1b-88d519109d10",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-02T01:59:17.966702Z",
     "iopub.status.busy": "2022-04-02T01:59:17.966392Z",
     "iopub.status.idle": "2022-04-02T01:59:17.971718Z",
     "shell.execute_reply": "2022-04-02T01:59:17.971131Z",
     "shell.execute_reply.started": "2022-04-02T01:59:17.966673Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 5, 11])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# axis=1，做max操作\n",
    "arr1.max(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "11d5be73-4b99-43e9-bfca-06b1fe10a8a6",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-02T02:05:31.983333Z",
     "iopub.status.busy": "2022-04-02T02:05:31.983084Z",
     "iopub.status.idle": "2022-04-02T02:05:31.989208Z",
     "shell.execute_reply": "2022-04-02T02:05:31.987895Z",
     "shell.execute_reply.started": "2022-04-02T02:05:31.983307Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 6,  7,  8,  9, 10, 11]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# axis=0，做delete操作\n",
    "np.delete(arr1, 0, axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "88f265f6-2d62-4124-bc69-2d4fd58e1bf6",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-02T02:07:56.271956Z",
     "iopub.status.busy": "2022-04-02T02:07:56.271689Z",
     "iopub.status.idle": "2022-04-02T02:07:56.277587Z",
     "shell.execute_reply": "2022-04-02T02:07:56.276818Z",
     "shell.execute_reply.started": "2022-04-02T02:07:56.271928Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1,  2,  3,  4,  5],\n",
       "       [ 7,  8,  9, 10, 11]])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# axis=1，做delete操作\n",
    "np.delete(arr1, 0, axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "3e0a4ce5-c8e2-416c-84f5-ebf4582db03d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-02T02:17:32.290251Z",
     "iopub.status.busy": "2022-04-02T02:17:32.289996Z",
     "iopub.status.idle": "2022-04-02T02:17:32.295636Z",
     "shell.execute_reply": "2022-04-02T02:17:32.294996Z",
     "shell.execute_reply.started": "2022-04-02T02:17:32.290224Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[ 0,  1,  2,  3,  4,  5],\n",
       "        [ 6,  7,  8,  9, 10, 11]],\n",
       "\n",
       "       [[12, 13, 14, 15, 16, 17],\n",
       "        [18, 19, 20, 21, 22, 23]]])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生成三维数组\n",
    "arr2 = np.arange(24).reshape(2,2,6)\n",
    "arr2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "cdd8fbe1-3e0a-4be1-ae9b-782afc245352",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-04-02T02:20:45.091085Z",
     "iopub.status.busy": "2022-04-02T02:20:45.090816Z",
     "iopub.status.idle": "2022-04-02T02:20:45.096529Z",
     "shell.execute_reply": "2022-04-02T02:20:45.095431Z",
     "shell.execute_reply.started": "2022-04-02T02:20:45.091058Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[12, 13, 14, 15, 16, 17],\n",
       "       [18, 19, 20, 21, 22, 23]])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# axis=0，做max操作\n",
    "arr2.max(axis=0)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
